package com.rivulet.dawn.service.service.business.impl;


import com.rivulet.dawn.api.model.business.DictionaryModel;
import com.rivulet.dawn.service.mapper.business.DictionaryMapper;
import com.rivulet.dawn.service.service.business.DictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class DictionaryServiceImpl implements DictionaryService {
    @Resource
    DictionaryMapper dictionaryMapper;

    @Override
    public Map<String, String> getCodeName(String dictType) {
        List<DictionaryModel> modelList = dictionaryMapper.selectByDictType(dictType);
        if (CollectionUtils.isEmpty(modelList)) {
            return Collections.emptyMap();
        }
        Map<String, String> map = new HashMap<>();
        try {
            for (DictionaryModel model : modelList) {
                map.put(model.getDictCode(), model.getDictName());
            }
        } catch (Exception e) {
            log.info("DictionaryService.getCodeName put error , because {}", e.getMessage());
        }
        return map;
    }
}
